(function() {
	var $ = {};
	/*===========================================================================================*/
	/*Application Utilities*/
	$.is_debug = function() {
		return (L('is_debug').toLowerCase() === 'true');
	};
	$.is_login_secure = function() {
		return (L('is_login_secure').toLowerCase() === 'true');
	};
	$.getInitData = function(callBack) {
		$.webservice().getInitData(function(e) {
			var result = JSON.parse(e);
			if (result.User) {
				$.currentUserEmailAddress(result.User.EmailAddress);
				$.currentUserName(result.User.UserName);
			}
			$.countries(result.Countries);
			$.allowReceiveNotification(result.AllowReceiveRetailerNotification);
			$.badgeNotification(result.UnreadNotificationNumber);
			$.badgeShoppingBag(result.CheckoutNotificationNumber);
			$.enquiriesEmail(result.EnquiriesEmail);
			callBack && callBack();
		});
	};
	$.openLoginWindow = function() {
		$.win('home').nav.push($.win('login'));
	};
	$.openTabgroupAndFocusToMyDesires = function() {
		$.ui('tabgroup').open({
			transition : Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT
		});
		$.win('my_desires').nav.reset();
		$.win('my_desires').display();
	};
	$.openMyDesiresWindow = function() {
		!Ti.UI.currentTab && $.ui('tabgroup').open({
			transition : Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT
		});
		$.win('my_desires').display();
	};
	$.openMyDesires = function() {
		$.ui('tabgroup').setActiveTab(0);
		$.ui('bottom').active(0);
		$.win('my_desires').nav.reset();
		$.win('my_desires').display();
	};
	$.openProductDetails = function(productVariantID, retailerStoreID, canGoBack, isScanned) {
		$.ui('tabgroup').setActiveTab(0);
		var activeIndex = canGoBack == false ? -1 : 0;
		$.ui('bottom').active(activeIndex);
		if ($.win('my_desires').nav.stack() > 0) {
			$.win('product_details').display(productVariantID, retailerStoreID, canGoBack, isScanned);
		} else {
			$.win('my_desires').nav.push($.win('product_details'));
			$.win('product_details').display(productVariantID, retailerStoreID, canGoBack, isScanned);
		}
	};
	$.openNotificationDetails = function(notificationID, canGoBack) {
		$.ui('tabgroup').setActiveTab(3);
		var activeIndex = canGoBack == false ? -1 : 3;
		$.ui('bottom').active(activeIndex);
		if ($.win('notifications').nav.stack() > 0) {
			$.win('notification_details').display(notificationID, canGoBack);
		} else {
			$.win('notifications').nav.push($.win('notification_details'));
			$.win('notification_details').display(notificationID, canGoBack);
		}
	};
	$.notificationGoToProductDetailPage = function() {
		$.i('notificationGoToProductDetailPage - currentUserID' + $.currentUserID());
		$.i('notificationGoToProductDetailPage - notificationUserID' + $.notificationUserID());
		if ($.isLoggedIn() && $.currentUserID() === $.notificationUserID()) {
			$.getInitData(function() {
				$.openProductDetails($.offerredProductVariantID(), $.offerredRetailerStoreID(), false);
				$.offerredProductVariantID(0);
				$.offerredRetailerStoreID(0);
				$.notificationUserID(0);
			});
		} else {
			$.i('notificationGoToProductDetailPage - alert current user does not have this notification.');
			var dialog = Ti.UI.createAlertDialog({
				message : L('productdetail_notification_description') + $.currentUserName(),
				title : L('productdetail_notification_title'),
				buttonNames : [L('ok_button')]
			});
			dialog.addEventListener('click', function(e) {
				$.openMyDesiresWindow();
			});
			dialog.show();
			$.offerredProductVariantID(0);
			$.offerredRetailerStoreID(0);
			$.notificationUserID(0);
		}
	};
	$.notificationGoToDetailPage = function() {
		$.i('notificationGoToDetailPage - currentUserID' + $.currentUserID());
		$.i('notificationGoToDetailPage - notificationUserID' + $.notificationUserID());
		if ($.isLoggedIn() && $.currentUserID() === $.notificationUserID()) {
			$.getInitData(function() {
				$.openNotificationDetails($.notificationDetailID(), false);
				$.notificationDetailID('');
				$.notificationUserID(0);
			});
		} else {
			$.i('notificationGoToDetailPage - alert current user does not have this notification.');
			var dialog = Ti.UI.createAlertDialog({
				message : L('notificationdetail_description') + $.currentUserName(),
				title : L('notificationdetail_title'),
				buttonNames : [L('ok_button')]
			});
			dialog.addEventListener('click', function(e) {
				$.openMyDesiresWindow();
			});
			dialog.show();
			$.notificationDetailID('');
			$.notificationUserID(0);
		}
	};
	$.addToShoppingBag = function(productVariantID, retailerStoreID, saleCampaignID) {
		$.mask();
		$.webservice().addToCart(productVariantID, retailerStoreID, saleCampaignID, function(e) {
			$.mask(false);
			var result = JSON.parse(e);
			if (result.Success) {
				$.a(L('message_add_to_cart_success'), L('message_add_to_cart_success_title'));
				$.updateBadges(result.CheckoutNotificationNumber, null);
			} else
				$.a(result.ErrorMeesage, L('message_error_title'));
		});
	};
	$.updateBadges = function(shoppingBagCount, notificationCount) {
		if (!$.isNull(shoppingBagCount))
			$.badgeShoppingBag(shoppingBagCount);
		if (!$.isNull(notificationCount))
			$.badgeNotification(notificationCount);
		$.ui('bottom').update_badge();
	};
	/*===========================================================================================*/
	/*String Utilities*/
	$.md5 = function(value) {
		return Ti.Utils.md5HexDigest(value);
	};
	$.e64 = function(value) {
		return Ti.Utils.base64encode(value);
	};
	$.d64 = function(value) {
		return Ti.Utils.base64decode(value);
	};
	$.trim = function(value) {
		if ( typeof value == 'undefined' || value == null)
			return '';
		return value.replace(/^\s+|\s+$/g, "");
	};
	$.isNull = function(value) {
		return typeof value == 'undefined' || value == null || $.trim(value.toString()) == '';
	};
	$.isValidEmail = function(email) {
		var eRegExp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
		var emailRegEx = new RegExp(eRegExp);
		return emailRegEx.test(email);
	};
	$.escape = function(input) {
		input = input.replace(/'/g, "\\'");
		return input;
	};
	$.encode_single_quotes = function(input) {
		input = input.replace(/'/g, "&squot;");
		input = input.replace(/"/g, "&quot;");
		return input;
	}
	$.decode_single_quotes = function(input) {
		input = input.replace(/&squot;/g, "'");
		input = input.replace(/&quot;/g, "\"");
		return input;
	}
	$.encode_uri = function(input) {
		if ($.isNull(input))
			return '';
		input = encodeURI(input);
		return input.replace(/&/g, "%26");
	};
	$.has_number = function(s) {
		var regex = /\d/g;
		return regex.test(s);
	};
	$.isValidDate = function(year, month, day) {
		year = parseInt(year, 10);
		month = parseInt(month, 10);
		day = parseInt(day, 10);
		var date = new Date(year, month - 1, day);
		var newYear = date.getFullYear();
		var newMonth = date.getMonth() + 1;
		var newDay = date.getDate();
		return newYear == year && newMonth == month && newDay == day;
	};
	$.isOver18 = function(yob, mob, dob) {
		year = parseInt(yob, 10);
		month = parseInt(mob, 10);
		day = parseInt(dob, 10);
		var today = new Date();
		today.setHours(0);
		today.setMinutes(0);
		today.setSeconds(0);
		var dob = new Date(year, month - 1, day);
		var age = Math.abs(today - dob);
		return age / (365.25 * 24 * 60 * 60 * 1000) >= 18;
	};
	$.dob = function(day, month, year) {
		if ($.isNull(day) || $.isNull(month) || $.isNull(year) || day < 0 || month < 0 || year < 0)
			return '';
		if (day < 10)
			day = '0' + day;
		if (month < 10)
			month = '0' + month;
		return day + '/' + month + '/' + year;
	};
	$.isFacebookAccount = function() {
		return $.currentUserName().indexOf('FB_Account_') > -1;
	};
	$.calculateOfferTimeLeft = function(endDate) {
		var timeArr = endDate.split(";");
		var offerEndDate = new Date(timeArr[0], timeArr[1] - 1, timeArr[2], timeArr[3], timeArr[4], timeArr[5]);
		var now = new Date();
		var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
		var timeLeft = offerEndDate - now_utc;
		var oneDay = 86400000;
		var oneHour = 3600000;
		var oneMinute = 60000;
		var days = Math.floor(timeLeft / oneDay);
		var hours = Math.floor((timeLeft - (days * oneDay)) / oneHour);
		var minutes = Math.floor((timeLeft - (days * oneDay) - (hours * oneHour)) / oneMinute);
		var timeLeftString = "";
		if (days > 0) {
			if (hours > 0) {
				if (minutes > 0) {
					timeLeftString = days + "d " + hours + "h " + minutes + "m";
				} else {
					timeLeftString = days + "d " + hours + "h";
				}
			} else {
				if (minutes > 0) {
					timeLeftString = days + "d " + minutes + "m";
				} else {
					timeLeftString = days + "d";
				}
			}
		} else {
			if (hours > 0) {
				if (minutes > 0) {
					timeLeftString = hours + "h " + minutes + "m";
				} else {
					timeLeftString = hours + "h";
				}
			} else {
				if (minutes > 0) {
					timeLeftString = minutes + "m";
				} else {
					timeLeftString = "1m";
				}
			}
		}
		return timeLeftString;
	};
	/*===========================================================================================*/
	/*Utilities*/
	$.scale = function(value, base) {
		base = base || 480;
		return value * 320 / base;
	}
	$.alert = function(message, title) {
		var dialog = Ti.UI.createAlertDialog({
			title : title || 'Alert',
			message : message,
			buttonNames : ['Ok'],
			cancel : 0
		});
		dialog.show();
	};
	$.confirm = function(message, title, callBack) {
		var dialog = Ti.UI.createAlertDialog({
			title : title || 'Confirmation',
			message : message,
			buttonNames : ['OK', 'Cancel'],
			cancel : 1
		});
		$.click(dialog, function(e) {
			if (e.index === 0)
				callBack && callBack();
		});
		dialog.show();
	};
	$.askFor = function(message, title, buttons, cancel, callBack) {
		cancel = $.isNull(cancel) ? 1 : cancel
		var dialog = Ti.UI.createAlertDialog({
			title : title || 'Confirmation',
			message : message,
			buttonNames : buttons || ['OK', 'Cancel'],
			cancel : cancel
		});
		$.click(dialog, function(e) {
			callBack && callBack(e.index != cancel);
		});
		dialog.show();
	};
	$.isFunction = function(obj) {
		return typeof obj == 'function';
	}
	$.on = function(event_name, obj, handler) {
		if (_.isArray(obj)) {
			if (_.isArray(event_name)) {
				_.each(obj, function(item) {
					_.each(event_name, function(_event) {
						item && item.addEventListener(_event, function(e) {
							$.isFunction(handler) && handler(e);
						});
					});
				});
			} else {
				_.each(obj, function(item) {
					item && item.addEventListener(event_name, function(e) {
						$.isFunction(handler) && handler(e);
					});
				});
			}
		} else {
			if (_.isArray(event_name)) {
				_.each(obj, function(item) {
					_.each(event_name, function(_event) {
						obj && obj.addEventListener(_event, function(e) {
							$.isFunction(handler) && handler(e);
						});
					});
				});
			} else {
				obj && obj.addEventListener(event_name, function(e) {
					$.isFunction(handler) && handler(e);
				});
			}
		}
	};
	$.tap = function(obj, handler) {
		$.on('singletap', obj, handler);
	};
	$.click = function(obj, handler) {
		$.on('click', obj, handler);
	};
	$.scrollEnd = function(obj, handler) {
		$.on('scrollEnd', obj, handler);
	};
	$.touch = function(obj, handler) {
		$.on('touchstart', obj, handler);
	};
	$.i = function(message) {
		Ti.API.info(String.format('%s', message));
	}
	$.w = function(message) {
		Ti.API.warn(String.format('%s', message));
	};
	$.d = function(message) {
		Ti.API.debug(String.format('%s', message));
	};
	$.l = function(message) {
		Ti.API.log(String.format('%s', message));
	};
	$.e = function(message) {
		Ti.API.error(String.format('%s', message));
	};
	$.a = function(message, title, buttons, callBack) {
		title = title || 'Alert';
		var dialog = Ti.UI.createAlertDialog({
			title : title,
			message : message,
			buttonNames : buttons || ['OK']
		});
		$.click(dialog, function(e) {
			callBack && callBack(e);
		});
		dialog.show();
	};
	$.config = function(key) {
		var result = '';
		var file = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'data/xml/config.xml');
		if (file.exists()) {
			var xmltext = file.read().text;
			var doc = Ti.XML.parseString(xmltext);
			var tag = doc.getElementsByTagName(key);
			if (tag && tag.item && tag.item.length > -1)
				result = tag.item(0).text;
		}
		return result;
	};
	$.mailTo = function(email) {
		var emailDialog = Ti.UI.createEmailDialog();
		emailDialog.subject = '';
		var emailTo = new Array();
		emailTo.push(email);
		emailDialog.toRecipients = emailTo;
		emailDialog.messageBody = '';
		emailDialog.open();
	};
	$.repeat = function(callBack, times) {
		for (var i = 0; i < times; i++) {
			_.delay(callBack, i * 200);
		}
	};
	$.resizeImageByWidth = function(localImagePath, width) {
		var img1 = Ti.UI.createImageView({
			image : localImagePath
		});
		var blob1 = img1.toImage();
		img1.width = width;
		img1.height = blob1.height * width / blob1.width;
		var img2 = Ti.UI.createImageView({
			image : localImagePath,
			width : img1.width,
			height : img1.height
		});
		var blob2 = img2.toImage();
		return blob2;
	};
	$.compressAndResize = function(blob, width, quality) {
		var ImageFactory = require('ti.imagefactory');
		var compressed = ImageFactory.compress(blob, quality);
		var img1 = Ti.UI.createImageView({
			image : compressed
		});
		var blob1 = img1.toImage();
		var height = blob1.height * width / blob1.width;
		var resized = ImageFactory.imageAsResized(compressed, {
			width : width,
			height : height
		});
		Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'tmp.jpg').write(resized);
		return Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'tmp.jpg').read();
	};
	/*===========================================================================================*/
	/*Device*/
	$.isIphone = function() {
		return Ti.Platform.osname == 'iphone';
	};
	$.isIphone5 = function() {
		return $.isIphone() && Ti.Platform.displayCaps.platformHeight > 500;
	};
	$.isIpad = function() {
		return Ti.Platform.osname == 'ipad';
	};
	$.isAndroid = function() {
		return Ti.Platform.osname == 'android';
	};
	$.deviceID = function() {
		return Ti.Platform.id;
	};
	$.deviceToken = function(value) {
		return $.prop('DeviceToken', value);
	};
	$.isOnline = function() {
		return Ti.Network.online;
	};
	$.isEnableLocationService = function() {
		return Ti.Geolocation && Ti.Geolocation.locationServicesEnabled;
	};
	$.version = function() {
		return Ti.App.version;
	};
	/*===========================================================================================*/
	/*Modules*/
	$.win = function(name) {
		return require('wins/' + name);
	};
	$.ui = function(name) {
		return require('ui/' + name);
	};
	$.model = function(name) {
		return require('models/' + name);
	};
	$.webservice = function() {
		return require(L('webservice'));
	};
	$.barcode = function() {
		return require(L('barcode'));
	};
	$.urban_airship = function() {
		return require(L('urban_airship'));
	};
	$.retailer_store = function() {
		return require(L('retailer_store'));
	};
	$.background_service = function() {
		return require(L('background_service'));
	};
	$.register_background_service = function() {
		Ti.API.info('Registering background services');
		if (Ti.App.currentService) {
			Ti.API.info('Removing background services');
			Ti.App.currentService.unregister();
		}
		var service = Ti.App.iOS.registerBackgroundService({
			url : '/utils/background_service.js'
		});
		Ti.API.info('*** Press home button to pause application ***');
	};
	$.gps = function() {
		return require(L('gps'));
	};
	$.facebook = function() {
		return require(L('facebook'));
	};
	$.cache = function() {
		return require(L('cache'));
	};
	$.cache_image = function(url, obj, callBack) {
		$.cache().cache_image.init(url, obj, callBack);
	};
	$.layout = function(fileName) {
		var filePath = 'layout/' + fileName + '.xml';
		// $.i('#LAYOUT : ' + filePath);
		return require('utils/xmlui').parseFile(filePath);
	};
	$.enum = function(fileName) {
		return require('enum/' + fileName);
	};
	$.photo = function() {
		return require('utils/photo');
	};
	/*===========================================================================================*/
	/*App Properties*/
	$.prop = function(_key, _value) {
		if ($.isNull(_value) && _value != '')
			return Ti.App.Properties.getString(_key, '');
		Ti.App.Properties.setString(_key, _value);
	};
	$.currentUserID = function(userID) {
		return $.prop('UserID', userID);
	};
	$.currentUserEmailAddress = function(value) {
		return $.prop('UserEmailAddress', value);
	};
	$.currentUserName = function(value) {
		return $.prop('UserName', value);
	};
	$.isLoggedIn = function() {
		return !$.isNull($.currentUserID());
	};
	$.badgeNotification = function(value) {
		return $.prop('BadgeNotification', value);
	};
	$.badgeShoppingBag = function(value) {
		return $.prop('BadgeShoppingBag', value);
	};
	$.myDesiresPagingSize = function(value) {
		return $.prop('MyDesiresPagingSize', value);
	};
	$.enquiriesEmail = function(value) {
		return $.prop('EnquiriesEmail', value);
	};
	$.offerredProductVariantID = function(value) {
		return $.prop('OfferredProductVariantID', value);
	};
	$.offerredRetailerStoreID = function(value) {
		return $.prop('OfferredRetailerStoreID', value);
	};
	$.offerredRetailerStoreID = function(value) {
		return $.prop('OfferredRetailerStoreID', value);
	};
	$.notificationUserID = function(value) {
		return $.prop('NotificationUserID', value);
	};
	$.notificationDetailID = function(value) {
		return $.prop('NotificationDetailID', value);
	};
	$.detectNearestLocationTimming = function(value) {
		return $.prop('DetectNearestLocationTimming', value);
	};
	$.mydesireRetailerItems = function(value) {
		return $.prop('MydesireRetailerItems', value);
	};
	$.ugdImageWidth = function(value) {
		return $.prop('UGDImageWidth', value);
	};
	$.ugdImageQuality = function(value) {
		return $.prop('UGDImageQuality', value);
	};
	/*===========================================================================================*/
	/*DataBase*/
	$.db = function(_key, _value) {
		if ($.isNull(_value) && _value != '')
			return $.cache().cache_data.get(_key);
		$.cache().cache_data.insert_or_update(_key, _value);
	};
	$.retailers = function(value) {
		return $.db('Retailers', value);
	};
	$.retailerStores = function(value) {
		return $.db('RetailerStores', value);
	};
	/*===========================================================================================*/
	/*UI Elements*/
	$.createWindow = function(wid, isInNavigationGroup) {
		var win = Ti.UI.createWindow({
			//fullscreen : false,
			//exitOnClose : false,
			//orientationModes : [Ti.UI.PORTRAIT],
			navBarHidden : true,
			tabBarHidden : false,
			backgroundColor : '#fff',
			zIndex : 1
		});
		win.wid = wid;
		$.on('focus', win, function() {
			$.currentWindow(win);
		});
		if (isInNavigationGroup === true)
			return $.createRootWindow(win);
		return win;
	};
	$.createRootWindow = function(win) {
		var rootWin = Ti.UI.createWindow({
			navBarHidden : true,
			tabBarHidden : false
		});
		var nav = Ti.UI.iPhone.createNavigationGroup();
		nav.window = win;
		var stackWindows = new Array();
		rootWin.nav = nav;
		nav.push = function(win) {
			var tmpStack = stackWindows;
			tmpStack.push(win);
			stackWindows = tmpStack;
			nav.open(win, {
				animated : true
			});
		};
		nav.pop = function() {
			var tmpStack = stackWindows;
			var clearWindow = tmpStack.pop();
			clearWindow && nav.close(clearWindow);
			stackWindows = tmpStack;
		};
		nav.reset = function() {
			var tmpStack = stackWindows;
			for (var i = 0, j = stackWindows.length; i < j; i++) {
				var clearWindow = tmpStack.pop();
				nav.close(clearWindow);
			}
			stackWindows = tmpStack;
		};
		nav.stack = function() {
			return stackWindows.length;
		};
		rootWin.add(nav);
		return rootWin;
	};
	$.openWindow = function(win) {
		win.open({
			modal : true,
			modalTransitionStyle : Ti.UI.iPhone.MODAL_TRANSITION_STYLE_FLIP_HORIZONTAL,
			modalStyle : Ti.UI.iPhone.MODAL_PRESENTATION_FULLSCREEN,
			navBarHidden : false
		});
	};
	$.commonScrollView = function(top, height) {
		top = top || L('nav_bar_height');
		height = height || $.mainContentHeight();
		var view = Ti.UI.createScrollView({
			contentWidth : L('content_width'),
			contentHeight : 'auto',
			top : top,
			showVerticalScrollIndicator : false,
			showHorizontalScrollIndicator : false,
			layout : 'vertical',
			height : height,
			width : L('content_width')
		});
		return view;
	};
	$.createButton = function(imagePath, style) {
		var button = Ti.UI.createButton(style);
		button.backgroundImage = imagePath;
		button.backgroundSelectedImage = imagePath;
		return button;
	};
	$.createWebView = function(url, style) {
		var webView = Ti.UI.createWebView(style);
		webView.url = url;
		webView.val = function(elementID, value) {
			if (value) {
				//value = $.encode_single_quotes(value);
				webView.evalJS("document.getElementById('" + elementID + "').innerHTML = '" + value + "';");
			} else {
				return webView.evalJS("document.getElementById('" + elementID + "').innerHTML");
			}
		};
		webView.css = function(elementID, style, value) {
			webView.evalJS("document.getElementById('" + elementID + "').style." + style + " = '" + value + "';");
		};
		webView.attr = function(elementID, attributeName, value) {
			webView.evalJS("document.getElementById('" + elementID + "').setAttribute('" + attributeName + "', '" + value + "');");
		};
		webView.onload = function(callBack) {
			webView.addEventListener('load', function() {
				callBack();
			});
		};
		webView.disableScroll = function() {
			webView.addEventListener("touchmove", function(e) {
				return false;
			});
		};
		return webView;
	};
	$.webview = {};
	$.webview.val = function(webView, elementID, value) {
		if (value) {
			value = $.encode_single_quotes(value);
			webView.evalJS("document.getElementById('" + elementID + "').innerHTML = '" + value + "';");
		} else {
			return webView.evalJS("document.getElementById('" + elementID + "').innerHTML");
		}
	};
	$.webview.css = function(webView, elementID, style, value) {
		webView.evalJS("document.getElementById('" + elementID + "').style." + style + " = '" + value + "';");
	};
	$.webview.attr = function(webView, elementID, attributeName, value) {
		webView.evalJS("document.getElementById('" + elementID + "').setAttribute('" + attributeName + "', '" + value + "');");
	};
	$.webview.onload = function(webView, callBack) {
		webView.addEventListener('load', function() {
			callBack && callBack();
		});
	};
	$.tmpView = function(height) {
		return Ti.UI.createView({
			width : '100%',
			height : height
		});
	};
	$.removeChildren = function(obj) {
		if (obj.children) {
			var children = obj.children.slice(0);
			for (var i = 0; i < children.length; i++) {
				obj.remove(children[i]);
				children[i] = null;
			}
		}
	};
	$.blur = function(items) {
		_.each(items, function(item) {
			item && item.blur();
		});
	};
	$.emptyTextFields = function(items) {
		_.each(items, function(item) {
			if (item)
				item.value = '';
		});
	};
	$.clean = function(obj) {
		var _window = Ti.UI.createWindow();
		_window.hide();
		_window.open();
		_window.add(obj);
		_window.close();
		_window = null;
		obj = null;
	};
	var _indicatorUI;
	$.indicator = function() {
		if ($.isNull(_indicatorUI)) {
			_indicatorUI = $.layout('popup/indicator');
			_indicatorUI.opended = false;
		}
		var ui = {};
		ui.show = function(showWhiteScreen) {
			if (!_indicatorUI.opended) {
				_indicatorUI.whiteScreen.visible = showWhiteScreen == true ? true : false;
				_indicatorUI.indicator.show();
				_indicatorUI.win.open();
				_indicatorUI.opended = true;
			}
		};
		ui.hide = function() {
			if (_indicatorUI.opended) {
				_indicatorUI.indicator.hide();
				_indicatorUI.win.close();
				_indicatorUI.opended = false;
			}
		};
		return ui;
	};
	var _softIndicatorUI;
	$.soft_indicator = function() {
		if ($.isNull(_softIndicatorUI))
			_softIndicatorUI = $.layout('popup/soft_indicator');
		var ui = {};
		ui.show = function(message, autoClose) {
			_softIndicatorUI.message.text = message;
			_softIndicatorUI.win.open();
			if (autoClose === true)
				_.delay(function() {
					ui.hide();
				}, 1500);
		};
		ui.hide = function() {
			_softIndicatorUI.win.close();
		};
		return ui;
	};
	$.mask = function(visibility, showWhiteScreen) {
		if (visibility != false)
			$.indicator().show(showWhiteScreen);
		else
			$.indicator().hide();
	};
	$.icon_info = function() {
		var view = Ti.UI.createView({
			width : 100,
			height : 50,
			// backgroundColor:'green',
			right : 0
		});
		var icon_info = Ti.UI.createImageView({
			width : $.scale(35),
			height : $.scale(35),
			right : 20,
			top : 10,
			image : L('icon_info')
		});
		view.add(icon_info);
		$.tap(view, function() {
			$.win('home').nav.push($.win('setting_details'));
			$.win('setting_details').update(L('code_how_it_work'));
		});
		return view;
	};
	$.page_title = function(title) {
		var label = Ti.UI.createLabel({
			text : title,
			height : '25dip',
			width : 'auto',
			color : L('color_orange'),
			font : {
				fontFamily : L('font_default'),
				fontSize : '17dip'
			},
			textAlign : 'left',
			top : 7,
			left : 0
		});
		return label;
	};
	$.page_title_skin = function(obj) {
		obj.width = 280;
		obj.height = Ti.UI.SIZE;
		obj.color = L('color_orange');
		obj.font = {
			fontFamily : L('font_default'),
			fontSize : '17dip'
		};
		obj.textAlign = 'left';
		obj.top = 7;
		//obj.left = 0;
	};
	$.opacity_show = function(obj, visibility) {
		if (visibility == false) {
			if (obj)
				obj.opacity = 0;
		} else {
			_.delay(function() {
				obj && obj.animate({
					duration : 1000,
					opacity : 1
				});
			}, 150);
		}
	};
	$.updateHeight = function(objs) {
		_.each(objs, function(obj) {
			obj && obj.updateLayout({
				height : Ti.UI.SIZE
			});
		});
	};
	$.setFont = function(objs) {
		_.each(objs, function(obj) {
			var _font = L('font_default');
			if (obj && obj.font) {
				if (obj.font.fontWeight == 'bold')
					_font = L('font_default_b');
				if (obj.font.fontStyle == 'italic')
					_font = L('font_default_i');
			}
			obj.font = {
				fontSize : (obj && obj.font && obj.font.fontSize) ? obj.font.fontSize : 14,
				fontWeight : (obj && obj.font && obj.font.fontWeight) ? obj.font.fontWeight : 'normal',
				fontFamily : _font
			};
		});
	};
	$.add = function(container, children) {
		_.each(children, function(child) {
			container.add(child);
		});
	};
	$.mainContentHeight = function(noTabBar) {
		if (noTabBar == true)
			return Ti.Platform.displayCaps.platformHeight - 65;
		return Ti.Platform.displayCaps.platformHeight - 115;
	};
	var currentWindow;
	$.currentWindow = function(obj) {
		if (obj) {
			currentWindow = obj;
		} else {
			return currentWindow;
		}
	};

	$.animate = function(obj, options, onComplete) {
		var animation = Ti.UI.createAnimation(options);
		$.on('complete', animation, function() {
			onComplete && onComplete();
		});
		obj.animate(animation);
	};

	/*===========================================================================================*/
	/*App data*/
	$.getStaticContent = function() {
		$.cache().cache_data.get(L('svGetStaticContent'));
		return JSON.parse($.cache().cache_data.get(L('svGetStaticContent'))).AppSettingContent;
	};
	var _countries = null;
	$.countries = function(data) {
		if ($.isNull(data))
			return _countries;
		_countries = data;
	};
	var _allowReceiveNotification = true;
	$.allowReceiveNotification = function(value) {
		if ($.isNull(value))
			return _allowReceiveNotification;
		_allowReceiveNotification = value;
	};
	$.userAuthToken = function(userName, password) {
		var userAuthToken = Ti.Utils.md5HexDigest(userName + ':' + L('authRealm') + ':' + password);
		return Ti.Utils.md5HexDigest('*100*' + userAuthToken + '#');
	};
	var _needToReloadMyDesires = false;
	$.needToReloadMyDesires = function(value) {
		if ($.isNull(value))
			return _needToReloadMyDesires;
		_needToReloadMyDesires = value;
	};

	module.exports = $;
})();
